package com.xiaohe66.web.domain.common.service;

import com.xiaohe66.common.ex.BusinessException;
import com.xiaohe66.common.value.ErrorCodeEnum;
import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.common.agg.Tag;
import com.xiaohe66.web.domain.common.repository.TagRepository;
import com.xiaohe66.web.domain.sys.sec.service.SecurityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaohe
 * @since 2023-01-29 11:53
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class TagService {

    private final TagRepository tagRepository;
    private final SecurityService securityService;

    public List<Tag> listByCreateId(AccountId createId) {

        // 权限检查
        if (!securityService.hasCurrentAccountPermission(createId)) {
            throw new BusinessException(ErrorCodeEnum.NOT_DATA_PERMISSION);
        }

        return tagRepository.listByCreateId(createId);
    }

}
